package controllers

import (
	"github.com/beego/beego/v2/server/web"
)

type AuthController struct {
	web.Controller
}

func (c *AuthController) Login() {
	if c.Ctx.Input.IsPost() {
		username := c.GetString("username")
		password := c.GetString("password")

		if username == "admin" && password == "P@ssword" {
			c.SetSession("user", username)
			c.Redirect("/products", 302)
			return
		} else {
			c.Data["Error"] = "用户名或密码错误"
		}
	}
	c.TplName = "login.tpl"
}

func (c *AuthController) Logout() {
	c.DestroySession()
	c.Redirect("/login", 302)
}
